﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;
using YiSha.Util;
using YiSha.Util.Model;
using YiSha.Entity;
using YiSha.Model;
using YiSha.Admin.Web.Controllers;
using YiSha.Entity.QixingManage;
using YiSha.Business.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Model.Result.QixingManage;
using YiSha.Web.Code;

namespace YiSha.Admin.Web.Areas.QixingManage.Controllers
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2023-03-19 19:46
    /// 描 述：订单详情控制器类
    /// </summary>
    [Area("QixingManage")]
    public class OrderDetailController :  BaseController
    {
        private OrderDetailBLL orderDetailBLL = new OrderDetailBLL();

        #region 视图功能
        [AuthorizeFilter("qixing:orderdetail:view")]
        public ActionResult OrderDetailIndex()
        {
            return View();
        }

        public ActionResult OrderDetailForm()
        {
            return View();
        }
        #endregion

        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("qixing:orderdetail:search")]
        public async Task<ActionResult> GetListJson(OrderDetailListParam param)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<OrderDetailEntity>> obj = await orderDetailBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:orderdetail:search")]
        public async Task<ActionResult> GetPageListJson(OrderDetailListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<OrderDetailEntity>> obj = await orderDetailBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:orderdetail:search")]
        public async Task<ActionResult> GetPageDetailList(OrderDetailListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<OrderDetailDto>> obj = await orderDetailBLL.GetPageDetailList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("qixing:orderdetail:search")]
        public async Task<ActionResult> GetPageColourDetailList(OrderDetailListParam param, Pagination pagination)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                param.tenant_id = operatorInfo.tenant_id;
            }
            TData<List<OrderDetailDto>> obj = await orderDetailBLL.GetPageColourDetailList(param, pagination);
            return Json(obj);
        }
        


        [HttpGet]
        public async Task<ActionResult> GetFormJson(long id)
        {
            TData<OrderDetailEntity> obj = await orderDetailBLL.GetEntity(id);
            return Json(obj);
        }
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("qixing:orderdetail:add,qixing:orderdetail:edit")]
        public async Task<ActionResult> SaveFormJson(OrderDetailEntity entity)
        {
            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (operatorInfo.IsSystem == 0)
            {
                entity.tenant_id = operatorInfo.tenant_id;
            }
            TData<string> obj = await orderDetailBLL.SaveForm(entity);
            return Json(obj);
        }

        [HttpPost]
        [AuthorizeFilter("qixing:orderdetail:add,qixing:orderdetail:edit")]
        public async Task<ActionResult> OrderDetailSaveFormJson(OrderDetailEntity entity)
        {
            TData<string> obj = await orderDetailBLL.OrderDetailSaveFormJson(entity);
            return Json(obj);
        }
        

        [HttpPost]
        [AuthorizeFilter("qixing:orderdetail:delete")]
        public async Task<ActionResult> DeleteFormJson(string ids)
        {
            TData obj = await orderDetailBLL.DeleteForm(ids);
            return Json(obj);
        }

        //public 
        #endregion
    }
}
